package algorithm_study.leecode;

import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;

public class IntegerReverse {
    public static int reverse(int x) {
        if(-9<=x&&x<=9){
            return x;
        }
        if(x==-2147483648){
            return 0;
        }
        int flag=1;
        if(x<0){
            flag=-1;
            x=-x;
        }
        Stack<Integer>reverse=new Stack<>();
           while (x!=0){
                 reverse.push(x%10);
                 x/=10;
           }
          //过滤特殊
        String s="";
        for (Integer integer : reverse) {
            s+=integer;
        }
        if(s.length()==10){
//            for(int i=0;i<5;i++){
//
//             }
            int front = Integer.parseInt(s.substring(0, 5));
            int after=Integer.parseInt(s.substring(5,10));
             if(front>21474){
                 return 0;
             }else if(front==21474){
                   if(after>83647){
                       return 0;
                   }
             }

        }
        return Integer.parseInt(s)*flag;
    }
    public static void main(String[] args) throws IOException {
//        System.out.println(Integer.MAX_VALUE);
//        System.out.println(Integer.MIN_VALUE);
//        System.out.println(reverse(-2147483648));
//        int[]arr=new int[10];
//        int i=2;
//        int j=3;
//        System.out.println(i++*j+i);
          BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(IntegerReverse.class.getClassLoader().getResourceAsStream("sTest.txt")));
          String s="一二三四五六";
        List<String>target=new ArrayList<>();
        String temp;
          while ((temp=bufferedReader.readLine())!=null){
                target.add(temp);
          }
        System.out.println(target);
          target.sort(new Comparator<String>() {
              @Override
              public int compare(String o1, String o2) {
                  return s.indexOf(o1.substring(0,1))-s.indexOf(o2.substring(0,1));
              }
          });
        System.out.println(target);
    }
}